package ar.uba.fi.tonyvaliente.signature;

/**
 * Implementa la función de hash propuesta por Brian Kernighan y Dennis Ritchie
 * en el libro "The C Programming Language".
 * @author santiago
 *
 */
public class BKDRHashFunction extends HashFunction {

	private int seed = 131;
	
	public BKDRHashFunction(int length) {
		super(length);
	}

	@Override
	public Number hash(String data) throws HashFunctionException {
		long seed = this.getSeed(); // 31 131 1313 13131 131313 etc..
		long hash = 0;

		for (int i = 0; i < data.length(); i++) {
			hash = (hash * seed) + data.charAt(i);
		}

		return Math.abs(hash%this.getLength());

	}

	public int getSeed(){
		return this.seed;
	}
	
	public void setSeed(int seed){
		this.seed = seed;
	}
}
